/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.venta;

import Controller.CajaC;
import Model.CajaM;
import Model.TiendaM;
import Util.ArrayListTableModel;
import Util.MiRenderBoton;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Maryluz
 */
public class frmIngreso extends javax.swing.JDialog {

    SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a", new Locale("ES"));
    public static SimpleDateFormat formateadorTabla = new SimpleDateFormat("dd/MM/yyyy", new Locale("ES"));
    Date fechaDate = new Date();
    String fecha = formateador.format(fechaDate);
    int idTiendaa;
    public frmIngreso(java.awt.Frame parent, boolean modal, int idTienda, TiendaM oM) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        txtFecha.setText(fecha);
        txtFecha2.setFormats("dd/MM/yyyy"); 
        txtTienda.setText(oM.getNomTienda().toUpperCase());
        txtResponsable.setText(oM.getNombres());
        idTiendaa= idTienda;
        cargarIngreso();
        configurarTabla();
        txtMonto.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                char caracter = e.getKeyChar();
                String texto = txtMonto.getText();


                // Verificar si la tecla pulsada no es un digito
                if (((caracter < '0') || (caracter > '9')) && (caracter != '.') && (caracter != '\b' /*corresponde a BACK_SPACE*/)) {
                    e.consume();  // ignorar el evento de teclado
                }

            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnNuevo = new javax.swing.JButton();
        txtMonto = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        btnGrabar = new javax.swing.JButton();
        txtConcepto = new javax.swing.JTextField();
        txtResponsable = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblIngresos = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        btnEliminar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        txtTienda = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtFecha = new javax.swing.JTextField();
        txtFecha2 = new org.jdesktop.swingx.JXDatePicker();
        jLabel1 = new javax.swing.JLabel();
        txtVerTodo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Movimientos de Caja .::. Ingresos");

        btnNuevo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Nuevo.png"))); // NOI18N
        btnNuevo.setText("NUEVO");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        txtMonto.setEditable(false);
        txtMonto.setFont(new java.awt.Font("Calibri", 0, 16)); // NOI18N
        txtMonto.setPreferredSize(new java.awt.Dimension(6, 35));

        btnGrabar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/mount.png"))); // NOI18N
        btnGrabar.setText("GUARDAR");
        btnGrabar.setEnabled(false);
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        txtConcepto.setEditable(false);
        txtConcepto.setFont(new java.awt.Font("Calibri", 0, 16)); // NOI18N
        txtConcepto.setPreferredSize(new java.awt.Dimension(6, 35));

        txtResponsable.setEditable(false);
        txtResponsable.setFont(new java.awt.Font("Calibri", 0, 16)); // NOI18N
        txtResponsable.setForeground(new java.awt.Color(0, 51, 102));
        txtResponsable.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        txtResponsable.setPreferredSize(new java.awt.Dimension(6, 35));

        jLabel4.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 0, 0));
        jLabel4.setText("Responsable:");

        tblIngresos.setModel(new ArrayListTableModel(
            new Object [][] {},
            new String [] {" FECHA"," RESPONSABLE"," CONCEPTO"," MONTO","",""}
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class,java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false,false,false,false,false,false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblIngresos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblIngresosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblIngresos);

        jLabel6.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(51, 0, 0));
        jLabel6.setText("Monto:");

        btnEliminar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/delete.png"))); // NOI18N
        btnEliminar.setText("CANCELAR");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(51, 0, 0));
        jLabel5.setText("Concepto:");

        txtTienda.setEditable(false);
        txtTienda.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        txtTienda.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtTienda.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        txtTienda.setPreferredSize(new java.awt.Dimension(6, 35));

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jLabel11.setFont(new java.awt.Font("Cambria", 1, 36)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 204, 0));
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("INGRESOS");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(229, 229, 229)
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(227, 227, 227))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel3.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(51, 0, 0));
        jLabel3.setText("Fecha");

        txtFecha.setEditable(false);
        txtFecha.setFont(new java.awt.Font("Calibri", 0, 16)); // NOI18N
        txtFecha.setForeground(new java.awt.Color(0, 51, 102));
        txtFecha.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFecha.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        txtFecha.setPreferredSize(new java.awt.Dimension(6, 35));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        txtFecha2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFecha2ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Filtrar por Fecha :");

        txtVerTodo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Database.png"))); // NOI18N
        txtVerTodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtVerTodoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(btnGrabar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(btnNuevo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(19, 19, 19)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtConcepto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(72, 72, 72))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(106, 178, Short.MAX_VALUE))))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtTienda, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtFecha2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(txtVerTodo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtTienda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtConcepto, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtVerTodo, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtFecha2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnGrabar, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24)
                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
//        ArrayListTableModel dtm = (ArrayListTableModel) tblIngresos.getModel(); //TableProducto es el nombre de mi tabla ;)
//        dtm.removeRow(tblIngresos.getSelectedRow());
        btnGrabar.setEnabled(false);
        txtConcepto.setText("");
        txtMonto.setText("");
        txtConcepto.setEditable(false);
        txtMonto.setEditable(false);
        tblIngresos.setEnabled(true);
        btnNuevo.setEnabled(true);
    }//GEN-LAST:event_btnEliminarActionPerformed

    @SuppressWarnings({"UseSpecificCatch", "CallToThreadDumpStack"})
    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
        if ("".equals(txtConcepto.getText().trim()) || "".equals(txtMonto.getText().trim())) {
            JOptionPane.showMessageDialog(null, "Complete lo campos.");
        } else {
            try {
                CajaM oCajaM = new CajaM();
                oCajaM.setConcepto(txtConcepto.getText());
                oCajaM.setRepresentante(txtResponsable.getText());
                oCajaM.setIngreso(Double.parseDouble(txtMonto.getText()));
                oCajaM.setIdtienda(idTiendaa); 
                
                CajaC oC = new CajaC();
                oC.agregarMovimientoCajaIngreso(oCajaM);
                JOptionPane.showMessageDialog(null, "Se registro el Ingreso a Caja.");
                tblIngresos.setEnabled(true);
                btnNuevo.setEnabled(true);
                btnGrabar.setEnabled(false); 
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        limpiarCajas();
        cargarIngreso();
    }//GEN-LAST:event_btnGrabarActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        txtConcepto.setEditable(true);
        txtMonto.setEditable(true);
        txtConcepto.requestFocus();
        btnGrabar.setEnabled(true);
        btnNuevo.setEnabled(false);
        tblIngresos.setEnabled(false);
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void tblIngresosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblIngresosMouseClicked

        if (tblIngresos.getRowCount() != 0) {
            int columNacedora = tblIngresos.getSelectedColumn();
            if (columNacedora == 4 && tblIngresos.isEnabled()) {
                try {

                    @SuppressWarnings("UnusedAssignment")
                    CajaM oCaja = new CajaM();
                    int filaBorrada = tblIngresos.getSelectedRow();
                    oCaja = (CajaM) tblIngresos.getValueAt(filaBorrada, 5);

                    int res = JOptionPane.showConfirmDialog(this, "Usted esta borrando este Movimiento en Caja !! \n¿Seguro que desea eliminarlo?", "Dialogo de Confirmación", JOptionPane.YES_NO_OPTION);
                    if (res == JOptionPane.YES_OPTION) {
                        new CajaC().deleteMovimientoCajaIngreso(oCaja);

                        if (tblIngresos.getRowCount() != 0) {
                            ArrayListTableModel dtm = (ArrayListTableModel) tblIngresos.getModel(); //TableProducto es el nombre de mi tabla ;)
                            dtm.removeRow(filaBorrada);
                        }
                        JOptionPane.showMessageDialog(rootPane, "Se elimino el registro con exito.");
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(rootPane, "Error al eliminar el registro. Verifique.");
                }

            }
            limpiarCajas();
            cargarIngreso();
        }
    }//GEN-LAST:event_tblIngresosMouseClicked

    private void txtVerTodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtVerTodoActionPerformed
        limpiarTablaModelo();
        cargarIngreso();
    }//GEN-LAST:event_txtVerTodoActionPerformed

    private void txtFecha2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFecha2ActionPerformed
        try {
            DateFormat fechaHora = new SimpleDateFormat("yyyy-MM-dd");
            String convertido = fechaHora.format(txtFecha2.getDate());
            CajaC oC = new CajaC();
            List<CajaM> oMs = oC.listarIngresos(convertido, idTiendaa);
            @SuppressWarnings("LocalVariableHidesMemberVariable")
            ArrayList oList;
            limpiarTablaModelo();
            if (oMs != null) {
                int size = oMs.size();
                for (int a = 0; a < size; a++) {
                    oList = new ArrayList();
                    oList.add(formateadorTabla.format(oMs.get(a).getFecha()));
                    oList.add("  " + oMs.get(a).getRepresentante().toUpperCase());
                    oList.add("  " + oMs.get(a).getConcepto().toUpperCase());
                    oList.add(oMs.get(a).getIngreso());
                    oList.add("");
                    oList.add(oMs.get(a));
                    ((ArrayListTableModel) tblIngresos.getModel()).addRow(oList);
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_txtFecha2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGrabar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    public static javax.swing.JTable tblIngresos;
    private javax.swing.JTextField txtConcepto;
    private javax.swing.JTextField txtFecha;
    private org.jdesktop.swingx.JXDatePicker txtFecha2;
    private javax.swing.JTextField txtMonto;
    private javax.swing.JTextField txtResponsable;
    private javax.swing.JTextField txtTienda;
    private javax.swing.JButton txtVerTodo;
    // End of variables declaration//GEN-END:variables

    private void limpiarCajas() {
        txtConcepto.setText("");
        txtMonto.setText("");
        txtConcepto.requestFocus();
    }

    private  void cargarIngreso() {
        CajaC oC = new CajaC();
        List<CajaM> oMs = oC.listarIngresos(idTiendaa);
        ArrayList oList;
        limpiarTablaModelo();
        if (oMs != null) {
            int size = oMs.size();
            for (int a = 0; a < size; a++) {
                oList = new ArrayList();
                oList.add(formateadorTabla.format(oMs.get(a).getFecha()));
                oList.add("  " + oMs.get(a).getRepresentante().toUpperCase());
                oList.add("  " + oMs.get(a).getConcepto().toUpperCase());
                oList.add(oMs.get(a).getIngreso());
                oList.add("");
                oList.add(oMs.get(a));
                ((ArrayListTableModel) tblIngresos.getModel()).addRow(oList);
            }
        }
    }

    public static void limpiarTablaModelo() {
        ArrayListTableModel oModelTbl = (ArrayListTableModel) tblIngresos.getModel();
        int i = oModelTbl.getRowCount();
        for (int a = 0; a < i; a++) {
            oModelTbl.removeRow(0);
        }
    }

    private void configurarTabla() {
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.CENTER);
        tblIngresos.setRowHeight(28);
        tblIngresos.getColumnModel().getColumn(0).setCellRenderer(tcr);
        tblIngresos.getColumnModel().getColumn(3).setCellRenderer(tcr);

        tblIngresos.getColumnModel().getColumn(0).setMinWidth(70);
        tblIngresos.getColumnModel().getColumn(0).setPreferredWidth(70);
        tblIngresos.getColumnModel().getColumn(0).setMaxWidth(70);
        tblIngresos.getColumnModel().getColumn(3).setMinWidth(70);
        tblIngresos.getColumnModel().getColumn(3).setPreferredWidth(70);
        tblIngresos.getColumnModel().getColumn(3).setMaxWidth(70);
        tblIngresos.getColumnModel().getColumn(4).setMinWidth(50);
        tblIngresos.getColumnModel().getColumn(4).setPreferredWidth(50);
        tblIngresos.getColumnModel().getColumn(4).setMaxWidth(50);
        tblIngresos.getColumnModel().getColumn(5).setMinWidth(0);
        tblIngresos.getColumnModel().getColumn(5).setPreferredWidth(0);
        tblIngresos.getColumnModel().getColumn(5).setMaxWidth(0);

        tblIngresos.getColumnModel().getColumn(4).setCellRenderer(new MiRenderBoton(true));
    }
}
